﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace qkview.Models
{

    [Table("UserProfile")]
    public class UserProfile
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int UserId { get; set; }
        [MaxLength(100)]
        public string Name { get; set; }
        [MaxLength(100)]
        public string Email { get; set; }
        [Required, MaxLength(50)]
        public string UserName { get; set; }
        public virtual ICollection<Board> Boards { get; set; }

    }


    public class Category
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int CategoryID { get; set; }
        [Required, MaxLength(50)]
        public string Name { get; set; }
        public virtual ICollection<Board> Boards { get; set; }
    }

    public class Board
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int BoardID { get; set; }
        [Required, MaxLength(50)]
        public string Title { get; set; }
        [MaxLength(50)]
        public string URLSlug { get; set; }
        [MaxLength(255)]
        public string Description { get; set; }
        public bool IsPrivate { get; set; }
        public DateTime CreatedDate { get; set; }       
        public int UserID { get; set; }         
        public int CategoryID { get; set; }
        public virtual ICollection<Note> Notes { get; set; }
    }

    public class Note
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int NoteID { get; set; }
        [Required, MaxLength(50)]
        public string Title { get; set; }
        public string Description { get; set; }
        public int SortIndex { get; set; }
        public DateTime CreatedDate { get; set; }
        public int BoardID { get; set; }
        public virtual ICollection<Section> Sections { get; set; }
    }

    public class Section
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int SectionID { get; set; }
        public int NoteID { get; set; }
        [Required, MaxLength(50)]
        public string Title { get; set; }
        [Required, MaxLength(500)]
        public string Summary { get; set; }
        public string Description { get; set; }
        public int SortIndex { get; set; }
    }


    public class QKContext : DbContext
    {
        public QKContext()
            : base("DefaultConnection")
        {
        }

        public DbSet<UserProfile> UserProfiles { get; set; }
        public DbSet<Category> Categories { get; set; }
        public DbSet<Board> Boards { get; set; }
        public DbSet<Note> Notes { get; set; }
        public DbSet<Section> Sections { get; set; }
    }
}